package com.nbjtjc.safe.api.danger;

import com.nbjtjc.common.validator.ValidatorUtils;
import com.nbjtjc.common.validator.group.DeleteGroup;
import com.nbjtjc.common.validator.group.UpdateGroup;
import com.nbjtjc.safe.annotation.SysLog;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.model.danger.DangerInspectList;
import com.nbjtjc.safe.model.know.SafeKnowledge;
import com.nbjtjc.safe.service.danger.DangerInspectListService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * @auther guqianbin
 * @date 2018/4/9 15:32
 * 隐患检查项
 **/
@RestController
@RequestMapping("/danger/inspectList")
@CrossOrigin("*")
public class DangerInspectListController {

    @Autowired
    private DangerInspectListService dangerInspectListService;

    @SysLog("添加隐患排模板表中的检查点")
    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public Result add(@RequestBody DangerInspectList dangerInspectList) {
        ValidatorUtils.validateEntity(dangerInspectList);
        Result result = new Result();
        result = dangerInspectListService.add(dangerInspectList);
        return result;
    }
    @SysLog("添加隐患排模板表中的检查点")
    @RequestMapping(value = "/addBatch", method = {RequestMethod.POST})
    public Result addBatch(@RequestBody List<DangerInspectList> dangerInspectLists) {
        Result result = new Result();
        result = dangerInspectListService.addBatch(dangerInspectLists);
        return result;
    }
    @SysLog("删除隐患排模板表中的检查点")
    @RequestMapping(value = "/delete", method = {RequestMethod.POST})
    public Result delete(@RequestBody DangerInspectList dangerInspectList) {
        ValidatorUtils.validateEntity(dangerInspectList, DeleteGroup.class);
        Result result = new Result();
        result = dangerInspectListService.delete(dangerInspectList);
        return result;
    }
    @SysLog("更新隐患排模板表中的检查点")
    @RequestMapping(value = "/update", method = {RequestMethod.POST})
    public Result update(@RequestBody DangerInspectList dangerInspectList) {
        ValidatorUtils.validateEntity(dangerInspectList, Default.class,UpdateGroup.class);
        Result result = new Result();
        result = dangerInspectListService.update(dangerInspectList);
        return result;
    }

    @RequestMapping(value = "/find", method = {RequestMethod.POST})
    public Result find(@RequestBody DangerInspectList dangerInspectList) {
        Result result = new Result();
        result = dangerInspectListService.find(dangerInspectList);
        return result;
    }

    @RequestMapping(value = "/findByDangerInspectIds", method = {RequestMethod.POST})
    public Result findByDangerInspectIds(@RequestParam("inspectIds")List<Integer> inspectIds) {
        Result result = new Result();
        result = dangerInspectListService.findByDangerInspectIds(inspectIds);
        return result;
    }
}
